using System.Configuration;

namespace Lync.Widget.Library.Configuration
{
    public class ActiveDirectoryGroupMemberElementCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new ActiveDirectoryGroupMemberElement();
        }
        protected override object GetElementKey(ConfigurationElement element)
        {
            var reference = (ActiveDirectoryGroupMemberElement)element;
            return reference.Sip;
        }
        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.BasicMap; }
        }
        protected override string ElementName
        {
            get { return "Member"; }
        }
        public ActiveDirectoryGroupMemberElement this[int index]
        {
            get { return (ActiveDirectoryGroupMemberElement)BaseGet(index); }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }
        new public ActiveDirectoryGroupMemberElement this[string key]
        {
            get { return (ActiveDirectoryGroupMemberElement)BaseGet(key); }
        }
        public bool ContainsKey(string key)
        {
            bool result = false;
            object[] keys = BaseGetAllKeys();
            foreach (object obj in keys)
            {
                if ((string)obj == key)
                {
                    result = true;
                    break;
                }
            }
            return result;
        }
    }
}